//
//  VMCIndicator.m
//  vmcshop
//
//  Created by toggle on 15/6/18.
//  Copyright (c) 2015年 idongler. All rights reserved.
//

#import "VMCIndicator.h"
#import "AnimationView.h"

@implementation VMCIndicator
{
    NSString *str;
}
+(instancetype)showIndicatorAddToView:(UIView *)view
{
	VMCIndicator *indicator = [[self alloc] initWithView:view];
	[view addSubview:indicator];
	return indicator;
}
+(BOOL)hideIndicatorForView:(UIView *)view
{
	VMCIndicator *indicator = [self HUDForView:view];
	if (indicator != nil)
	{
		[indicator removeFromSuperview];
		return YES;
	}
	return NO;
}

- (id)initWithView:(UIView *)view
{
	NSAssert(view, @"View must not be nil.");
	VMCIndicator *indicator = [self initWithFrame:view.bounds];
    self.backgroundColor = [UIColor clearColor];
    str = @"加载中，请稍后...";
    CGSize size = [str sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f]}];
	AnimationView *avi = [[AnimationView alloc]initWithFrame:CGRectMake(100, 200, size.width+25, 30)];
    avi.titleStr = str;
	[indicator addSubview:avi];
	avi.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2,[UIScreen mainScreen].bounds.size.height/2);
	return indicator;
}

+ (instancetype)HUDForView:(UIView *)view
{
	NSEnumerator *subviewsEnum = [view.subviews reverseObjectEnumerator];
	for (UIView *subview in subviewsEnum) {
		if ([subview isKindOfClass:self])
		{
			return (VMCIndicator *)subview;
		}
	}
	return nil;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
